package com.example.suyuan.controller;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ResponseStatusException;

@RestController
@RequestMapping("/api/auth") // 定义基础路径
public class AuthController {

    @PostMapping("/login") // 定义登录路由
    public String login(@RequestParam String username, @RequestParam String password) {
        // 调用服务层进行验证
        boolean isAuthenticated = authenticate(username, password);
        if (isAuthenticated) {
            return "Login successful";
        } else {
            throw new ResponseStatusException(HttpStatus.UNAUTHORIZED, "Invalid username or password");
        }
    }

    private boolean authenticate(String username, String password) {
        // 这里应该是调用用户服务进行验证的逻辑
        return "admin".equals(username) && "password".equals(password);
    }
}